<?php
namespace app\cms\upgrade;

use think\Db;

class U5{
    public static function up(){
        
        
        $result = Db::name('cms_field')->where('name','mv_url')->value('type');
        if($result=='file'){
            query("ALTER TABLE  `qb_cms_content3` CHANGE  `mv_url`  `mv_url` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT  '视频地址'");
            $array = Db::name('cms_content3')->column('id,title,mv_url');
            foreach($array AS $rs){
                $data = [
                    'mv_url'=>json_encode([
                        [
                            'url'=>$rs['mv_url'],
                            'title'=>$rs['title']
                        ],
                    ]),
                ];
                Db::name('cms_content3')->where('id',$rs['id'])->update($data);
            }
            query("UPDATE `qb_cms_field` SET  `type` =  'files2',`field_type` =  'text NOT NULL'  WHERE `name` = 'mv_url';");	
        }
        
        
        $result = Db::name('cms_field')->where('name','voice_url')->value('type');
        if($result=='file'){
            query("ALTER TABLE  `qb_cms_content4` CHANGE  `voice_url`  `voice_url` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT  '音频地址'");
            $array = Db::name('cms_content4')->column('id,title,voice_url');
            foreach($array AS $rs){
                $data = [
                    'voice_url'=>json_encode([
                        [
                            'url'=>$rs['voice_url'],
                            'title'=>$rs['title']
                        ],
                    ]),
                ];
                Db::name('cms_content4')->where('id',$rs['id'])->update($data);
            }
            query("UPDATE `qb_cms_field` SET  `type` =  'files2',`field_type` =  'text NOT NULL'  WHERE `name` = 'voice_url';");
        }
	    
	  
	}
}


